<?php
/**
 * Author: 孙武 QQ:1228746736
 * Date: 2018/3/7
 * Time: 9:54
 */
namespace Sunwu\Err;
//提示类
class ErrInfo
{
    private $err;
    private $data;

    public function __construct()
    {
        $this->err = new Err();
    }

    public function infoEmpty()
    {
        return $this->err->err(10000);

    }

    public function infoSuccess()
    {
        return $this->err->err(0);
    }

    public function infoDbSelect()
    {
        
    }


    public function infoDbUpdate()
    {
        
    }


    public function infoDbDelete()
    {
        
    }

    public function infoDbSave()
    {
        
    }
}


//错误基类
class Err
{
    private $errno;
    private $errmsg;
    private $maps;

    public function __construct()
    {
        $mapname = __DIR__ . "/maps.ini";
        if (!file_exists($mapname)) throw new \Exception('当前目录下的maps.ini文件不存在,请手动创建');
        $this->maps = parse_ini_file($mapname);
    }

    public function err($errno)
    {
        $this->setErrnoAndErrmsg($errno);
        return $this->formate();

    }


    private function formate()
    {
        return [
            'errno' => $this->errno,
            'errmsg' => $this->errmsg,
        ];
    }

    private function setErrnoAndErrmsg($errno)
    {
        $this->errno  = (int)$errno;
        $this->errmsg = $this->maps[$this->errno];
    }


}



